class SessionsController < ApplicationController
  def create
    auth_hash = request.env['omniauth.auth']
    @user=User.find session[:user_id]
    if auth_hash[:provider]=='facebook'
      session[:facebook_token]=auth_hash[:credentials][:token]
      @user.facebook_id=auth_hash[:uid]
    elsif auth_hash[:provider]=='twitter'
      session[:twitter_token]=auth_hash[:credentials][:token]
      session[:twitter_secret]=auth_hash[:credentials][:secret]
      @user.twitter_id=auth_hash[:uid]
    elsif auth_hash[:provider]=='linkedin'
      session[:linkedin_token]=auth_hash[:credentials][:token]
      session[:linkedin_secret]=auth_hash[:credentials][:secret]
      @user.linkedin_id=auth_hash[:uid]
    end
    logger.debug '============TOKENS==================';
    logger.debug  'Facebook Token:'+(session[:facebook_token].present?() ? session[:facebook_token]:'')
    logger.debug  'Twitter_Token:'+(session[:twitter_token].present?() ? session[:twitter_token]:'')
    logger.debug  'Twitter_Secret:'+(session[:twitter_secret].present?() ? session[:twitter_secret]:'')
    logger.debug  'LinkedIn_Token:'+(session[:linkedin_token].present?() ? session[:linkedin_token]:'')
    logger.debug  'LinkedIn_Token:'+(session[:linkedin_secret].present?() ? session[:linkedin_secret]:'')
    logger.debug '==============================';
    redirect_to hub_path
    @user.save
  end
end